{extend name="admininfo/admininfo" /}
{block name='main'}


<h2>角色列表</h2>
<a class="btn btn-default btn-success" href="{:url('admin/Role/addshow')}">
 添加角色
</a>
<table class="table table-hover table-bordered" style="text-align: center;">


    <tr>
        <th style="text-align: center;">
            id
        </th>
        <th style="text-align: center;">
           角色名
        </th>
        <th style="text-align: center;">
            操作
        </th>
    </tr>

    {foreach $list as $v}
    <tr id="{$v['id']}">
        <td>
            {$v['id']}
        </td>
        <td>
            {$v['role']}
        </td> 
        <td >
            <div class="row clearfix">
                <!--<div class="col-md-12 column" >-->
                
                <a  href='{:url("admin/Role/edit?id=".$v["id"])}' class="btn btn-default  btn-success ">编辑</a>

                <a  class="btn btn-default btn-danger del"  data_id="{$v['id']}">删除</a>

            </div>
        </td>
    </tr>
    {/foreach}

</table>



<script>
   $(function(){
        $('.del').click(function(){
            var a = confirm('你确定删除吗!!!!!');
            if (a) {

                var id = $(this).attr('data_id');
                $.ajax({
                    type:'post',
                    url:  '/admin/Role/delete',
                    data:{ 'id': id },
                    dataType:'json',
                    success: function(data){

                        console.log(data);
                        if (data>0) {
                            $('#'+id).remove();
                            alert('删除成功');
                        }else{
                            alert('删除失败');
                        }  
                    },
                    error:function(){
                        alert('ajax执行失败');
                    }

                })
            }
        })
    })
</script>

{/block}